class bgRun extends eui.Component implements  eui.UIComponent {
	public constructor() {
		super();
		this.skinName="bgRunSkin"
		// this.addEventListener(egret.TouchEvent.ADDED_TO_STAGE,this.childrenCreated,this)
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}

	//
	
	private bgRun
	private cont
	public pet1
	public pet2
	public pet3
	public pet4
	

	//设置循环播放
	private playAnimation(target: egret.tween.TweenGroup, isLoop: boolean): void {
		if (isLoop) {
			for (var key in target.items) {
				target.items[key].props = { loop: true};
			}
		}
		target.play();
	}
	
	protected childrenCreated():void
	{	
		super.childrenCreated();

		//背景滚动
		this.playAnimation(this.bgRun,true)

	
	//英雄奔跑动画
		let Movie = new egret.MovieClipDataFactory(RES.getRes("HeroRun_json"),RES.getRes("HeroRun_png"))	
		let runMovie = new egret.MovieClip(Movie.generateMovieClipData("heroRun"))
		this.addChild(runMovie)
		runMovie.play(-1)
		runMovie.x =250;
		runMovie.y =100;
	//英雄自由落体运动	
		let Dow = new egret.Timer(20,-1)
		Dow.addEventListener(egret.TimerEvent.TIMER,()=>{
			runMovie.y+=4
		},this)
		Dow.start()
	//点击跳跃	
		this.stage.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{
				egret.Tween.get(runMovie).to({y:runMovie.y-250},500)
		},this)



		//循环实例踏板对象
		//第一条木条
		this.pet1 = new Pedal2(runMovie)
		// this.cont.addChild(this.pet1)
	//循环的函数	
		let Timer = new egret.Timer(1500,-1)
		Timer.addEventListener(egret.TimerEvent.TIMER,()=>{
			//实例化踏板对象
			let pet3 = new Pedal2(runMovie)
			this.cont.addChild(pet3)
		},this)
		Timer.start()

		//所有木条的碰撞
/*
	帧函数，每一个都进行触发
*/
		this.addEventListener(egret.Event.ENTER_FRAME,()=>{
			if(runMovie.y + runMovie.height*.5 > this.stage.stageHeight){
				Dow.stop()
				runMovie.stop()
			}		
		},this)
		
	}

	
	
}